/*
 * HSM Proxy Project.
 * Copyright (C) 2013 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.hsm.admin.webapp;

import javax.faces.event.ValueChangeEvent;
import javax.inject.Named;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import be.fedict.hsm.admin.webapp.jsf.ViewScoped;
import be.fedict.hsm.entity.KeyStoreType;

@Named("hsmProxyKeyStoreType")
@ViewScoped
public class KeyStoreTypeController {

	private static final Log LOG = LogFactory
			.getLog(KeyStoreTypeController.class);

	private KeyStoreType keyStoreType;

	public void changeType(ValueChangeEvent valueChangeEvent) {
		this.keyStoreType = (KeyStoreType) valueChangeEvent.getNewValue();
		LOG.debug("change key store type: " + this.keyStoreType);
	}

	public boolean getNoSlotListIndex() {
		if (null == this.keyStoreType) {
			/*
			 * PKCS#11 is the default selection.
			 */
			return false;
		}
		return this.keyStoreType != KeyStoreType.PKCS11;
	}
}
